2020-2021 Sunseeker Telemetry and Lighting System
pmm_ex1_lpm4-5.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 /*******************************************************************************
33  * MSP430i2xx Power Management Module - Enter LPM4.5
34  *
35  * Description: In this example, the device is setup to enter LPM4.5. Before
36  * the device enters LPM4.5 the LED is turned on to indicate it has entered
37  * LPM4.5. Exiting LPM4.5 is triggered by a Low to High transition on P2.1 that
38  * causes a reset of the device. Once reset the LPM4.5 interrupt is set and the
39  * device begins to simply toggle the LED. This example demonstrates how to
40  * setup the device for LPM4.5 and interrupt successfully from it.
41  *
42  *
43  * MSP430i2041
44  * ------------------
45  * /|\| |
46  * | | P1.4|-->LED
47  * --|RST |
48  * | |
49  * | |
50  * | P2.1|-->Wakeup
51  * | |
52  * | |
53  *
54  * Author: Zack Lalanne
55  ******************************************************************************/
56 
57 #include "driverlib.h"
58 
59 #define GPIO_PIN_ALL (GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3 | \
60  GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7)
61 
62 int main(void) {
63 
64  WDT_hold(WDT_BASE);
65 
66  // Configure GPIO for low current numbers while in LPM4.5
67  GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN_ALL);
68  GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN_ALL);
69  GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN_ALL);
70  GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN_ALL);
71 
72  // Determine if coming out of LPM 4.5
73  if(PMM_getInterruptStatus(PMM_LPM45_INTERRUPT)) {
74 
75  PMM_clearInterrupt(PMM_LPM45_INTERRUPT);
76 
77  // Need to unlock IO after exiting LPM4.5 so LED will blink
78  PMM_unlockIOConfiguration();
79 
80  } else {
81 
82  // Configure exit of LPM4.5 on P2.1 interrupt
83  GPIO_setAsInputPin(GPIO_PORT_P2, GPIO_PIN1);
84  GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN1,
85  GPIO_LOW_TO_HIGH_TRANSITION);
86  GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN1);
87  GPIO_enableInterrupt(GPIO_PORT_P2, GPIO_PIN1);
88 
89  // Turn on LED to indicate we are about to enter LPM4.5
90  GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN4);
91 
92  // Turn off regulator so we can enter LPM4.5
93  PMM_setRegulatorStatus(PMM_REGULATOR_OFF);
94 
95  __bis_SR_register(LPM4_bits);
96  }
97 
98  // Slow down clock so we can see LED blink
99  // Configure MCLK = ~1MHz
100  CS_initClockSignal(CS_MCLK, CS_CLOCK_DIVIDER_16);
101 
102  while(1) {
103  GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN4);
104  __delay_cycles(100000);
105  }
106 }
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)
int main(void)
#define GPIO_PIN_ALL